package com.work.rochegroupproperty.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.work.rochegroupproperty.dto.SearchTodoRequest;
import com.work.rochegroupproperty.entity.Todo;
import com.work.rochegroupproperty.mapper.TodolistMapper;
import com.work.rochegroupproperty.service.ITodolistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class TodolistServiceImpl extends ServiceImpl<TodolistMapper, Todo> implements ITodolistService {

    @Override
    public IPage<Todo> searchTodos(SearchTodoRequest req) {
        // 分页对象
        Page<Todo> page = new Page<>(req.getPage(), req.getSize());

        // 构造查询条件：用户 ID + (标题或描述包含关键词)
        QueryWrapper<Todo> wrapper = new QueryWrapper<>();
        wrapper.eq("belonging_user_id", req.getUserId())
                .and(w -> w
                        .like("title", req.getKeyword())
                        .or()
                        .like("description", req.getKeyword())
                );

        return this.page(page, wrapper);
    }

}
